package com.sy.shopping.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sy.shopping.dto.ActionResult;
import com.sy.shopping.entity.UserA;
import com.sy.shopping.mapper.UserAMapper;
import com.sy.shopping.service.UserAService;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
@Slf4j
public class UserAServiceImpl implements UserAService {
    @Resource
    private UserAMapper userAMapper;

    /**
     * 根据用户名获取用户信息
     */
    @Override
    public Object getUserAByUsername(String username) {
        List<UserA> user = userAMapper.selectList(new QueryWrapper<UserA>().eq("username", username));
        if (CollectionUtils.isEmpty(user)) {
            return new ActionResult(false, "当前用户不存在...");
        }
        log.info("超级管理员:" + user);
        return new ActionResult(true,user);
    }

    @Override
    public Object verifyUserAPassword(HashMap<String,Object> input) {
        UserA userA = userAMapper.selectOne(new QueryWrapper<UserA>().eq("id", input.get("userId").toString()));
        if (!userA.getPassword().equals(input.get("password").toString())) {
            return new ActionResult(false, "输入的密码不正确...");
        }
        return new ActionResult(true);
    }
}
